package com.ruoyi.web.utils.influxdb;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Date;

@Data
public class DeviceHistoryDataParam {

    private String deviceId;

    private Long productId;

    private String startTime;

    private String endTime;

    @ApiModelProperty(value = "日期类型，1历史数据，2按日统计，3按月统计")
    private Integer type;

    private Integer pageNum;

    private Integer pageSize;

    public long getStartTimeSecond() {
        return DateUtil.parse(startTime, DatePattern.NORM_DATE_PATTERN).getTime() / 1000;
    }

    public long getEndTimeSecond() {
        return DateUtil.parse(endTime, DatePattern.NORM_DATE_PATTERN).getTime() / 1000 + 86400; //一天86400秒
    }

    public int getOffset(){
        return  (pageNum - 1) * pageSize;
    }

    public DeviceHistoryDataParam(String deviceId, Long productId,int day) {
        this.deviceId = deviceId;
        this.productId = productId;

        this.setEndTime(DateUtil.format(new Date(),DatePattern.NORM_DATE_PATTERN));
        this.setStartTime(DateUtil.offsetDay(new Date() , -day + 1).toString(DatePattern.NORM_DATE_PATTERN));
    }
}
